import '../models/todo.dart';
import '../../../core/network/api_client.dart';

abstract class TodoRepository {
  Future<List<Todo>> getTodos();
}

class ApiTodoRepository implements TodoRepository {
  final ApiClient _apiClient = ApiClient();

  @override
  Future<List<Todo>> getTodos() async {
    try {
      final response = await _apiClient.get('/todos');
      final List<dynamic> data = response.data;
      return data.map((json) => Todo.fromJson(json)).toList();
    } catch (e) {
      rethrow;
    }
  }
}

class MockTodoRepository implements TodoRepository {
  @override
  Future<List<Todo>> getTodos() async {
    // 模拟网络延迟
    await Future.delayed(const Duration(seconds: 2));
    
    return [
      const Todo(id: 1, title: '学习 Flutter MVVM 架构', completed: false),
      const Todo(id: 2, title: '实现网络请求层', completed: true),
      const Todo(id: 3, title: '添加错误处理机制', completed: false),
      const Todo(id: 4, title: '优化用户体验', completed: false),
    ];
  }
}